package cn.iocoder.yudao.module.measure.service.warning.impl;


import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
import cn.iocoder.yudao.module.measure.dal.dataobject.point.MeasurePointInfoDO;
import cn.iocoder.yudao.module.measure.dal.mysql.warning.BusinessDeviceUploadWarningConfigMapper;
import cn.iocoder.yudao.module.measure.service.point.BusinessMeasurePointInfoService;
import cn.iocoder.yudao.module.measure.service.warning.BusinessDeviceUploadWarningConfigService;
import cn.iocoder.yudao.module.measure.service.warning.BusinessDeviceWarnPersonConfigService;
import cn.iocoder.yudao.module.measure.dal.dataobject.warning.BusinessDeviceUploadWarningConfig;
import cn.iocoder.yudao.module.measure.dal.dataobject.warning.BusinessDeviceWarnPersonConfig;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 业务实现类
 * 设备上传数据报警设置
 * </p>
 *
 * @author zhengbzh
 * @date 2025-06-03 15:38:10
 * @create [2025-06-03 15:38:10] [zhengbzh] [代码生成器生成]
 */
@Slf4j
@RequiredArgsConstructor
@Service("businessDeviceUploadWarningConfigServiceImpl")
@Transactional(readOnly = true)
public class BusinessDeviceUploadWarningConfigServiceImpl implements BusinessDeviceUploadWarningConfigService {


    @Resource
    private BusinessDeviceUploadWarningConfigMapper businessDeviceUploadWarningConfigMapper;

    @Resource
    private BusinessMeasurePointInfoService measurePointInfoService;

    @Resource
    private BusinessDeviceWarnPersonConfigService businessDeviceWarnPersonConfigService;


    @Override
    @Cacheable(value = "deviceUploadWarningConfig", key = "#deviceId")
    public List<BusinessDeviceUploadWarningConfig> getDeviceWarningConfig(String deviceId) {
        TenantContextHolder.setIgnore(true); // 设置忽略租户信息
        return businessDeviceUploadWarningConfigMapper.getDeviceWarningConfig(deviceId);
    }

    @Override
    public String getMeasureNameStr(Long measureId) {
        TenantContextHolder.setIgnore(true); // 设置忽略租户信息
        MeasurePointInfoDO measurePointInfo = measurePointInfoService.getMeasurePointInfo(measureId);
        return measurePointInfo.getMeasurePointName();
    }

    @Override
    public List<BusinessDeviceWarnPersonConfig> getWarningPerson(Long measureId) {
        TenantContextHolder.setIgnore(true); // 设置忽略租户信息
        return businessDeviceWarnPersonConfigService.getWarningPersonByMeasurePointId(measureId);
    }
}


